package com.xiaobai.bo;

import lombok.Data;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @description: 教学楼
 * @author: 小白白
 * @create: 2021-11-26
 **/

@Data
public class FreeClassroomBuilding {

    /**
     * 楼名
     */
    private String name;

    /**
     * 各个教室(按照节次排序),非map,因为教室杂多
     */
    private List<FreeClassroomItem> list;

    /**
     * 不参与序列化,辅助检索
     */
    private transient Map<String, FreeClassroomItem> map;

    public FreeClassroomBuilding(String name) {
        this.name = name;
        this.list = new ArrayList<>();
        this.map = new HashMap<>();
    }

    /**
     * 放入空闲教室
     * @param name 教师名称
     * @param index 空闲节次[1~5]
     */
    public void addItem(String name, Integer capacity, int index) {
        FreeClassroomItem freeClassroomItem = this.map.get(name);
        if (freeClassroomItem != null) {
            freeClassroomItem.addFree(index);
        } else {
            freeClassroomItem = new FreeClassroomItem(name, capacity);
            freeClassroomItem.addFree(index);
            this.list.add(freeClassroomItem);
            this.map.put(name, freeClassroomItem);
        }
    }

}
